﻿using System;
using Missbot.Common;
using Missbot.Core.Common;
using Missbot.Model.MsgInfos;

namespace Missbot.Core.SyntaxChecker.ParamCheckers
{
    public class UserParam : IParam
    {
        public Type CheckType => typeof(InstanceUser);

        public (bool isValid, object param, string unsolvedMsg) Check(string msg)
        {
            var (param, unsolvedMsg) = msg.SplitParam();
            if (!param.StartsWith('@') || param.Length <= 1)
            {
                return (false, null, null);
            }

            var userName = param[1..];
            var user = Requestor.GetUserByUserName(userName);
            return user == null ? (false, null, null) : (true, user, unsolvedMsg);
        }
    }
}